//项目的网络请求
import axios from 'axios'

axios.defaults.baseURL='http://localhost:8080/mobilebank';

import {usePersonStore} from '../store/person.js'

//post请求
const postRequst=(url,data)=>{
	return axios({
		method:'post',
		url:url,
		data:data,
		headers:{
			'Content-Type': 'application/json',
			'Authorization':localStorage.getItem("token")
		}
	});
}

//get请求
const getRequst=(url,data)=>{
	return axios({
		method: 'get',
		url: url,
		params: data,
		headers:{
			'Authorization':localStorage.getItem("token")
		}
	});
}

const asyncPostRequst=async (url,data)=>{
    return  new Promise((resolve,reject) => {
        axios({
              method: 'post',
              url: url,
              data: data,
              headers:{
                'Content-Type': 'application/json',
                'Authorization':localStorage.getItem("token")
              }
        }).then(resp=>{  
            resolve(resp.data)
        }).catch(err=>{
            reject({result:false})
        })
    })
}

const asyncGetRequst=async (url,data)=>{
    return  new Promise((resolve,reject) => {
        axios({
              method: 'get',
              url: url,
              params: data,
              headers:{
                'Content-Type': 'application/json',
                'Authorization':localStorage.getItem("token")
              }
        }).then(resp=>{  
            resolve(resp.data)
        }).catch(err=>{
            reject({result:false})
        })
    })
}


//登录请求
export const loginApiUser=(mobile)=>{
    return postRequst("/personinfo/login",mobile);
}


//客服登录
export const loginApiService=(loginFeedback)=>{
    return postRequst("/feedback/flogin",loginFeedback);
}
 
//根据令牌获取登录信息
export const refushLoginApi=()=>{
    return postRequst("/personinfo/refush");
}
 
//根据令牌获取登录信息
export const refushLoginApi2=async ()=>{
    return asyncPostRequst("/personinfo/refush");
}

//注册请求
export const registerApi=(data)=>{
    return postRequst("/personinfo/register",data);
}
 
 
 //验证码
 export const getVerificationCodeApi = (data) => {
   return getRequst("/personinfo/verify",data);
 }
 
 
//获取信息

export const getUserInfo = (data)=>{
	return getRequst("/personinfo/selectAll",data)
}
//修改信息
export const changeUserInfo = (personinfo) =>{
	return postRequst("/personinfo/updateinfo",personinfo)
}

//提问
export const getQue = (data)=>{
	return postRequst("/feedback/feedback",data)
}

//查看历史问题
export const checkQue = (data)=>{
	return postRequst("/feedback/getfeedbackbya",data)
}

//客服查看问题
export const selectQue = (data)=>{
	return postRequst("/feedback//getanswerfeedback",data)

//客服反馈
export const answerQue = (Feedback)=>{
	return postRequst("/feedback/answerfeedback",Feedback)
}

//查询账户
export const getAccount = (token)=>{
	return getRequst("/account/showaccount",token)
}
//转账
export const transrecipient = (requestAccount) =>{
	return postRequst("/recipient/transferAccounts",requestAccount)
}

//取款
export const accountout = (data) =>{
	return postRequst("/account/accountout",data)
}

//存款
export const accountin = (data) =>{
	return postRequst("/account/accountin",data)
}

//查询交易记录--所有
export const checkAll = (data) =>{
	return postRequst("/transrecord/queryAll",data)
}

//查询交易记录--时间
export const checkTime = (data) =>{
	return postRequst("/transrecord/date",data)
}

//查询交易记录--类型
export const checkType = (data) =>{
	return postRequst("/transrecord/type",data)
}

//查询交易记录--金额
export const checkMoney = (data) =>{
	return postRequst("/transrecord/money",data)
}

